<extend name="Layout/ins_page" />
<block name="content">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php if (!session_id()) session_start();date_default_timezone_set('PRC'); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>授权列表</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link href="/sap/demo.css" rel="stylesheet" type="text/css" />
    <script src="/sap/scripts/boot.js" type="text/javascript"></script>
	<style>
	
	</style>
    
</head>
<body >

 <fieldset id="fd1" style="">
        <br/>
        <div  id='fm1'>
        <div class="fieldset-body" style="padding-left: 20px;">
        
      <span class='span'> 平台代码</span>:  <div class="mini-autocomplete" style="width:250px;"  popupWidth="400" textField="id" valueField="id"  id='U_CardCode' name='U_CardCode'
        url="/sale/getOCRDByCode_Auth" value="<?php  if(isset($_SESSION['u_code'])){echo $_SESSION['u_code'];}?>" text="<?php  if(isset($_SESSION['u_code'])){echo $_SESSION['u_code'];}?>"  onvaluechanged="onValueChanged" >     
        <div property="columns">
            <div header="客户代码" field="id" width="30"></div>
            <div header="客户名称" field="text"></div>
        </div>
    </div>
    
   
          <span class='span'>平台名称: </span> <input type="input" class='mini-textbox' id='cname-show' style="width: 250px"/>
    <br/><br/>
        <span class='span'>   查询品牌:</span>  <input class="mini-buttonedit" onbuttonclick="onButtonEditBrand" id='key' name='key' style="width: 250px"/>
           <span class='span'>添加时间:</span>
		<input id="start" class="mini-datepicker"  format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true" valueType='string' value="<?php echo date('Y-m-d',time()-86400*7)?>"/>
		<input id="end" class="mini-datepicker"  format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true" valueType='string' value="<?php echo date('Y-m-d H:i:s')?>" />

		<span class='span'> 筛选:</span><input id="s_type" class="mini-combobox" style="width:150px;" textField="text" valueField="id" emptyText="请选择..."
    data="[{id:0,text:'全部'},{id:1,text:'未失效'},{id:2,text:'已失效'}]" value="0"  required="true" allowInput="true" showNullItem="true" nullItemText="请选择..."/>
            <div>
                <span class='span'>查询类目:</span>
                <input class="mini-buttonedit" onbuttonclick="onButtonEditCategory" id='thecategory' name='thecategory' style="width: 250px"/>
            </div>
            <div>
                <span class='span'>查询级别:</span>
                <input class='mini-textbox' id='thelevel' name='thelevel' style="width: 250px"/>
            </div>

    <a class="mini-button" onclick="search()"   enabled="" id='query-bt'  style="margin-top: 5px">&nbsp;&nbsp;查询&nbsp;&nbsp;</a>
    <a class="mini-button" onclick="export_excel()"   enabled="" id='query-bt'  style="margin-top: 5px">&nbsp;&nbsp;导出&nbsp;&nbsp;</a>
    <!--<a class="mini-button" onclick="downselected()"   enabled="" id='query-bt'  style="margin-top: 5px">&nbsp;&nbsp;下载选中授权附件&nbsp;&nbsp;</a>-->
    </fieldset>
  
   
    <div id="tabs1" class="mini-tabs" activeIndex="0" style="width:100%;margin-top: 5px;overflow:auto;" plain="false"
    buttons="#tabsButtons"
>
    <div title=" " >
   
   <div id="datagrid1" class="mini-datagrid" style="height:430px;width: 100%;" 
        url="/auth/getIndexData" idField="id"
        allowResize="true" 
        allowCellEdit="true" allowCellSelect="true" multiSelect="true"
        allowCellValid="true" oncellvalidation="" 
    >
    
        <div property="columns">
         <div type="checkcolumn" ></div>     
           <div field="code"  headerAlign="center"  >平台代码
              
            </div>   
             <div field="cname"  headerAlign="center"  >平台名称
               
            </div>    
            
             <div field="categorytxt"  headerAlign="center" width="200px">平台类目
               
            </div>           
            
            <div field="brand_name"  headerAlign="center"  >品牌
              
            </div> 
            
            
            <div field="level"  headerAlign="center"  >授权级别
                
            </div> 
            
            <div field="auth_chain"  headerAlign="center">授权链
                
            </div> 
            
             <div field="status"  headerAlign="center">状态
               
            </div> 
            
            
              <div field="start"   headerAlign="center"  >授权开始时间
                <input property="editor" class="mini-datepicker" valueType='string' style="width:100%;" format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true" />
            </div>  
            
              <div field="end"   headerAlign="center"  >授权结束时间
                <input property="editor" class="mini-datepicker"  valueType='string' style="width:100%;" format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true" />
            </div>  
            
             <div field="ctime"   headerAlign="center"  >添加时间
                
            </div>  
            
            <div field="note"   headerAlign="center"  >备注</div>

            <div field="examine_status" type="comboboxcolumn"   headerAlign="center"  >审核状态
                <!--<input property="editor" class="mini-combobox" style="width:100%;" data="typeOfProcess" />-->
            </div>

           <div name="action" width="100" headerAlign="center">#</div>
        </div>
    </div>
    
    </div>
    <!-- <div title="Tab2" iconCls="" >
        2
    </div> -->
</div>

  <div id='editForm1' style="display: none;">
    <br/>
    <a class="mini-button" onclick="onButtonEdit()" enabled="" id='query-bt' >&nbsp;&nbsp;添加物料&nbsp;&nbsp;</a>
    <a class="mini-button" onclick="save()" enabled="" id='query-bt' >&nbsp;&nbsp;保存&nbsp;&nbsp;</a>
  </div>
</body>
<script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
        grid.setPageSize(50);
        search();
        grid.on("drawcell", function (e) {
        var record = e.record,
        column = e.column,
        field = e.field,
        value = e.value;

            //格式化日期
            if (field == "U_FroTime"||field=='U_ToTime') {
                if (mini.isDate(value)) e.cellHtml = mini.formatDate(value, "yyyy-MM-dd HH:mm:ss");
				
            }

            //action列，超连接操作按钮
            if (column.name == "action") {
                e.cellStyle = "text-align:center";
                e.cellHtml = '<a href="/auth/save?id=' + record.id + '"/>编辑/审核</a>&nbsp; ';//+'<a href="/auth/down?id=' + record.id + '"/>下载附件</a>&nbsp; ';
                 
            }

            if(record.examine_status!=1)
                e.cellStyle = "background:#f9a8a8";

            if (field == "examine_status") {
                e.cellHtml =value==1?"通过":(value==0?"待审核":'未通过') ;
            }

        });

        function search(){
    		var start = mini.get('start').getValue();
    		var end   = mini.get('end').getValue();
			var code  = mini.get('U_CardCode').getValue();
			var s_type= mini.get('s_type').getValue(); 
			var key= mini.get('key').getValue(); //查询品牌
            var thecategory= mini.get('thecategory').getValue(); //查询类目
            var thelevel= mini.get('thelevel').getValue(); //查询级别
			grid.load({'code':code,'start':start,'end':end,type:s_type,key:key,'thecategory':thecategory,thelevel:thelevel,});
        }

        function export_excel(){
            var start = mini.get('start').getValue();
            var end   = mini.get('end').getValue();
            var code  = mini.get('U_CardCode').getValue();
            var s_type= mini.get('s_type').getValue();
            var key= mini.get('key').getValue(); //查询品牌
            var thecategory= mini.get('thecategory').getValue(); //查询类目
            var thelevel= mini.get('thelevel').getValue(); //查询级别
            //grid.load({'code':code,'start':start,'end':end,type:s_type,key:key,'thecategory':thecategory,thelevel:thelevel,});

            var f=document.createElement("form");
            f.action="/Auth/exportIndexData";
            f.method="post";
            f.innerHTML=" <input type='hidden' name='code' value='"+code+"'/>"+
                "<input type='hidden' name='start' value='"+start+"'/>" +
                "<input type='hidden' name='end' value='"+end+"'/>" +
                "<input type='hidden' name='type' value='"+s_type+"'/>" +
                "<input type='hidden' name='key' value='"+key+"'/>" +
                "<input type='hidden' name='thecategory' value='"+thecategory+"'/>" +
                "<input type='hidden' name='thelevel' value='"+thelevel+"'/>"
            ;
            document.body.appendChild(f);
            f.submit();
        }

        function onButtonEdit(e) {
            var btnEdit = this;
            mini.open({
                url:  "/sap/goods_select.php",
                title: "选择物料",
                width: 650,
                height: 380,
                ondestroy: function (action) {
                    //if (action == "close") return false;
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);    //必须
                        if (data) {
                        	data.Code=mini.get('U_CardCode').getValue();
                        	data.U_ItemCode=data.catid;
                        	data.U_ItemName=data.name;
                        	data.U_TypeOption=data.U_TypeOption;
                            grid.addRow(data, 0);
                           
                        }
                    }

                }
            });
        }

        function save() {
        	var data = grid.getChanges()[0];
        	if(data==null){
				mini.alert('无更新数据');
				return;
            }

            if(data.U_FroTime==null||data.U_ToTime==null){
             mini.alert('上下架时间不能为空');   
             return ;
             }

            var form = new mini.Form("#fm1");            
            var fmdata = form.getData();      //获取表单多个控件的数据
            if(data.Code==''){
            	data.Code=fmdata.U_CardCode;
             }

           
            if(data.Code==''){
				mini.alert('请选择客户');
				return;
              }
           var json = mini.encode(data); 
           alert(json);
             mini.mask({
                el: document.body,
                cls: 'mini-mask-loading',
                html: '保存中...'
            }); 
            $.ajax({
                url: "/goods/saveRelation",
                data: { data: json},
                type: "post",
                dataType:'json',
                success: function (data) {
                   if(data.code==0){
                	    mini.unmask(document.body);
						mini.alert('保存成功!');
						search();
						return ;
                   }else{
                	   mini.unmask(document.body);
                	   mini.alert(data.msg);
                       }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });
        }


   	 function onValueChanged(e) {
            
            var item = e.selected;
            if (item) { 
                mini.get('cname-show').setValue(item.text);  
            }
        }
   	 
   	 function downselected(){
   		 var rows = grid.getSelecteds();
   		 if(rows.length<1){
   			 mini.alert('请选择要下载的授权！');
   			 return ;
   		 }
   		 var ids = '';
   		 for(var i=0;i<rows.length;i++){
   			 ids+=rows[i].id+',';
   		 }
   		
   		 window.open("/auth/dwonSelected?ids="+ids);
   	 }

        function onButtonEditBrand(e) {
            var btnEdit = this;
            mini.open({
                url:  "/index.php?m=&c=SapSupplier&a=brandselect",
                title: "选择品牌",
                width: 650,
                height: 380,
                ondestroy: function (action) {
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);    //必须
                        if (data) {
                            btnEdit.setValue(data.b_id);//b_id
                            btnEdit.setText(data.b_name);
                        }
                    }

                }
            });

        }

        function onButtonEditCategory(e) {

            var btnEdit = this;
            mini.open({
                url:  "/Auth/selectcategories",
                showMaxButton: false,
                title: "选择类目",
                width: 450,
                height: 450,
                ondestroy: function (action) {
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);
                        if (data) {
                            btnEdit.setValue(data.id);
                            btnEdit.setText(data.text);
                        }
                    }
                }
            });


        }
        
    </script>

<script type="text/javascript">
    var typeOfProcess = [{ id: 0, text: '待审核' }, { id: 1, text: '通过'}, { id: -1, text: '未通过'}];
</script>

</html>
</block>
